package com.kust.smarthome.web.socketserver;


import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.HashMap;

public class Server implements Runnable {

    private String UID;
    private Socket socket;
    private HashMap<String,Socket> cilentsocket = new HashMap<String, Socket>();


    public Server(String UID, Socket socket) {
        this.UID = UID;
        this.socket = socket;
    }

    public void run() {

        while(true) {
            //如果socket关闭，则跳出循环
            if(socket.isClosed())break;
            //这里该线程就可以接收客户端的信息.
            try {

//                ObjectInputStream oi = new ObjectInputStream(socket.getInputStream());
//                Message m = (Message) oi.readObject();
//
//                //对从客户端取得的消息进行类型判断，然后做相应的处理
//                if(m.getOperate().equals("send")){
//                    ObjectOutputStream os = new ObjectOutputStream(ManageClientThread.hm.get(m.getToID().trim()).getOutputStream());//获取输出流
//                    os.writeObject(m);
//                }
//


            } catch (Exception e) {
                //如果有异常，则关闭socket
                try {
                    socket.close();

                } catch (IOException ioException) {
                    ioException.printStackTrace();
                }
            }

        }
        System.out.println(UID+"关闭连接");

    }


}